package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.BookOrder;
import com.xuetang9.t9.hotel.beans.DiningTable;
import com.xuetang9.t9.hotel.mapper.IBookOrderMapper;
import com.xuetang9.t9.hotel.mapper.IDiningTableMapper;
import com.xuetang9.t9.hotel.services.IBookOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ProjectName: MyHotelProject
 * @Package: com.xuetang9.t9.hotel.service.impl
 * @ClassName: BookOrderService
 * @Author: ChinaHp
 * @Description: 预定订单服务层接口实现类
 * @Date: 2020/2/24 17:24
 * @Version: 1.0
 */
@Service
public class BookOrderService implements IBookOrderService {
    @Autowired
    private IBookOrderMapper mapper;
    @Autowired
    private IDiningTableMapper diningTableMapper;

    @Override
    public boolean add(BookOrder bookOrder) {
        //修改餐桌的状态
        DiningTable diningTable = diningTableMapper.select(bookOrder.getTableNum());
        diningTable.setState("已预约");
        diningTableMapper.update(diningTable);
        return mapper.insert(bookOrder)> 0;
    }

    @Override
    public boolean remove(Integer id) {
        return mapper.delete(id) > 0;
    }

    @Override
    public List<BookOrder> query() {
        return mapper.select();
    }

    @Override
    public boolean alter(BookOrder bookOrder) {
        return mapper.alter(bookOrder) > 0;
    }

    @Override
    public List<BookOrder> todayTheOrder() {
        return mapper.todayTheOrder();
    }

    @Override
    public List<BookOrder> queryStateOrder(String state) {
        return mapper.queryByState(state);
    }

    @Override
    public BookOrder selectById(Integer id) {
        return mapper.selectBookOrder(id);
    }
}
